<template>
  <div class="view-fill">
    <div v-if="!modifyInfo.visible" class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        title="省采收货管理详情"
        @returnBack="returnBack"
      >
        <template v-slot:full-button>
          <el-button
            v-if="
              $permission('provinceReceipt:update') && infoList.data.status === 1
            "
            @click="update"
            >修改</el-button
          >
          <el-button v-if="canSubmit" @click="submit">提交 </el-button>
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t("basic_information") }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="infoList">
              <template v-slot:basic-networkProductType>
               {{ infoList.data.networkProductTypeValue }}
              </template>
            </basic-information>
          </div>
        </div>

        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip :text="$t('detailInfo')"></Tooltip>

          </div>
          <div class="model-panel-body">
            <div class="flex_full_item">
              <!-- 表格 -->
              <page-table
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                v-model:data="tableInfo.data"
                :api="tableInfo.api"
                :pager="false"
                :check-box="false"
                :tab-index="true"
                :query="filterInfo.query"
                :field-list="tableInfo.fieldList"
                :isDynamic="true"
              >
                <template v-slot:col-receivingQty="scope">
                  <span v-if="scope.row.receivingQty">
                    {{ scope.row.receivingQty + scope.row.preNetworkUnit }}
                  </span>
                  <span v-else>-</span>
                </template>
                <template v-slot:col-deliverQty="scope">
                  <span v-if="scope.row.deliverQty">
                    {{ scope.row.deliverQty + scope.row.preNetworkUnit }}
                  </span>
                  <span v-else>-</span>
                </template>
                <template v-slot:col-returnQty="scope">
                  <span v-if="scope.row.returnQty">
                    {{ scope.row.returnQty + scope.row.preNetworkUnit }}
                  </span>
                  <span v-else>-</span>
                </template>
                <template v-slot:col-preNetworkPrice="scope">
                  <span v-if="scope.row.preNetworkPrice">
                    {{ scope.row.preNetworkPrice + '元/' + scope.row.preNetworkUnit }}
                  </span>
                  <span v-else>-</span>
                </template>
              </page-table>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>

    <modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :tableKey="modifyInfo.tableKey"
      :orderId="modifyInfo.orderId"
      :purchAccording="infoList.data.purchAccording"
      :is-copy="modifyInfo.isCopy"
      @returnModify="returnModify"
    />
  </div>
</template>

<script setup name="receiptOrderDetailView">
import { modifyProvinceReceivingOrder, detailsProvinceReceivingOrder,submitProvinceReceivingOrder } from "@/api/province";
import { getCustomizeSetting } from "@/api/customize";
import modify from "./modify";
import _ from "lodash";

const emits = defineEmits();
const { proxy } = getCurrentInstance();
const props = defineProps(["visible", "orderId"]);
const tableKey = ref(
  "provinceReceivingOrderDetail-com.slip.spd.entity.vo.provincePlatform.ProvinceReceivingOrderDetailVO"
);
const infoList = ref({
  data: {},
  fieldList: [
    { label: "收货单号", value: "orderNo", type: "text" },
    { label: "状态", value: "statusValue", type: "text" },
    { label: "挂网产品类型", value: "networkProductType", type: "slot" },
    { label: "供应商", value: "supplierName", type: "text" },
    { label: "创建人", value: "createUserName", type: "text" },
    { label: "创建时间", value: "createTime", type: "text" },
  ],
});
// 过滤相关配置
const filterInfo = ref({
  sortArr: [],
  copyQueryMap: {},
  query: {
    queryMap: {
      orderId: {
        queryType: "EQUALS",
        queryCategory: "AND",
        value: null,
      },
    },
    queryParams: {},
  },
  searchList: [],
  searchBtn: [],
  btnList: [],
});

// 表格相关
const tableInfo = ref({
  api: undefined,

  fieldList: [],
  refresh: 1,
  initCurpage: 1,
  data: [],
});

const modifyInfo = ref({
  visible: false,
  title: "",
  orderId: "",
  tableKey: "",
  isCopy: false,
});

const showDialog = computed({
  get() {
    return props.visible;
  },
  set(newValue) {
    emits("update:visible", newValue); // 更新父组件shows
  },
});

const canSubmit = computed(() => {
  return (
    proxy.$permission("provinceReceipt:submit") && infoList.value.data.status === 1
  );
});

setData();
function setData() {
  let obj = {
    receivingQty: {
      label: "收货数量",
      value: "receivingQty",
      type: "slot",
      minWidth: "250px",
      hidden: true,
    },
    deliverQty: {
      label: "配送数量",
      value: "deliverQty",
      type: "slot",
      minWidth: "250px",
      hidden: true,
    },
    returnQty: {
      label: "退货数量",
      value: "returnQty",
      type: "slot",
      minWidth: "250px",
      hidden: true,
    },
    preNetworkPrice: {
      label: "省采单价",
      value: "preNetworkPrice",
      type: "slot",
      minWidth: "250px",
      hidden: true,
    },
  };
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...obj,
  });
  getCustomize();
}

function returnModify() {
  if (props.orderId) {
    getCustomize();
  }
}

function getOrderInfo(orderId) {
  detailsProvinceReceivingOrder(orderId).then((resp) => {
    if (resp && resp.success) {
      infoList.value["data"] = resp.data;
    }
  });
}
function update() {
  modifyInfo.value.visible = true;
  modifyInfo.value.title = "修改省采订单";
  // 显示信息
  modifyInfo.value.orderId = props.orderId;
}
function submit() {
  const ids = []
  ids.push(infoList.value.data.id);
  submitProvinceReceivingOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getOrderInfo(props.orderId);
    }
  });
}

function getCustomize() {
  let _tableInfo = tableInfo.value;
  let param = {
    tableKey: tableKey.value,
  };
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data;
      _tableInfo.fieldList = proxy.$fn.setFieldList(
        _tableInfo.fieldList,
        data.detail
      );
      filterInfo.value.query.customizeUserVO = data;
      filterInfo.value.query.queryMap.orderId.value = props.orderId;
      _tableInfo.api = modifyProvinceReceivingOrder;
      getOrderInfo(props.orderId);
      getList();
    }
  });
}
function returnBack() {
  emits("returnBack", false);
}
function getList() {
  modifyProvinceReceivingOrder(filterInfo.value.query).then((resp) => {
    if (resp && resp.success) {
      tableInfo.value.data = resp.data;
    }
  });
}
</script>
<style scoped lang="scss">
:deep(.page-table) > .el-table {
  overflow-y: hidden;
}
.model-panel-title {
  display: flex;
  align-items: center;
  .model-tips {
    display: flex;
    align-items: center;
    margin-left: 10px;
    color: #909399;
    .model-tips-nearly,
    .model-tips-expire {
      display: block;
      margin-left: 5px;
      width: 17px;
      height: 17px;
    }
    .model-tips-nearly {
      background: #fceacb;
    }
    .model-tips-expire {
      background: #f5e4e4;
    }
  }
}
:deep(.el-table) {
  .nearly-row {
    background: #fceacb;
  }
  .expire-row {
    background: #f5e4e4;
  }
}
</style>
